﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using DacSanMienTayOBJ;

public partial class Proccess_ProccessLockAndUnlockCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LockUnlockCategory();
    }

    private void LockUnlockCategory()
    {
        try
        {
            //int modId = (int)Session["ModId"];
            int cateID = int.Parse(Request["cateID"]);
            string type = Request["type"];
            int vt = int.Parse(Request["vt"]);
            StringBuilder builder = new StringBuilder();
            if (type == "lock")
            {
                bool rs = CategoryBusiness.UpdateVisibleCategory(cateID, 0, ConnectionType.AdminConnection);
                if (rs)
                {
                    Category cate = CategoryBusiness.GetCategoryDetail(cateID, ConnectionType.AdminConnection);
                    string cateName = cate.CategoryName;
                    string parentCateName = cate.ParentCategoryName;
                    string cateImage = Utility.modHost + "/" + cate.CategoryImage;
                    string status = "";
                    if (cate.IsVisible == 1)
                    {
                        status = "Active";
                    }
                    else
                    {
                        status = "Inactive";
                    }

                    builder.Append("<tr id=\"trCategory" + vt + "\">");
                    builder.Append("<td>" + cateName + " </td>");
                    builder.Append("<td><img src=\"" + cateImage + "\" width=\"100px\" height=\"100px\" /></td>");
                    builder.Append("<td>" + parentCateName + "</td>");
                    builder.Append("<td>" + cate.MetaKeyword + "</td>");
                    builder.Append("<td>" + status + "</td>");

                    builder.Append("<td><span style=\"color:Blue; cursor:pointer\" title=\"" + cateName + "\" id=\"" + cate.MetaKeyword + "\"  onclick=\"ShowInfoCategory('" + cate.CategoryID + "','" + cate.ParentCategoryID + "','" + cateImage + "',this.title,this.id,'" + cate.IsSection + "')\">Chỉnh sữa</span></td>");
                    builder.Append("<td>");
                    if (cate.IsVisible == 1)
                    {
                        builder.Append("<input type=\"button\" title=\"" + cate.CategoryID + "\"  value=\"Khóa\" onclick=\"LockAndUnlockCategory(this.title,'lock','" + vt + "')\" />");
                    }
                    else
                    {
                        builder.Append("<input type=\"button\" title=\"" + cate.CategoryID + "\"  value=\"Mở khóa\" onclick=\"LockAndUnlockCategory(this.title,'unlock','" + vt + "')\" />");

                    }
                    builder.Append("</td>");
                    Response.Write(builder);
                }
                else
                {
                    Response.Write("lockfaile");
                }
            }
            else if (type == "unlock")
            {
                bool rs = CategoryBusiness.UpdateVisibleCategory(cateID, 1, ConnectionType.AdminConnection);
                if (rs)
                {
                    Category cate = CategoryBusiness.GetCategoryDetail(cateID, ConnectionType.AdminConnection);
                    string cateName = cate.CategoryName;
                    string parentCateName = cate.ParentCategoryName;
                    string cateImage = Utility.modHost + "/" + cate.CategoryImage;
                    string status = "";
                    if (cate.IsVisible == 1)
                    {
                        status = "Active";
                    }
                    else
                    {
                        status = "Inactive";
                    }

                    builder.Append("<tr id=\"trCategory" + vt + "\">");
                    builder.Append("<td>" + cateName + " </td>");
                    builder.Append("<td><img src=\"" + cateImage + "\" width=\"100px\" height=\"100px\" /></td>");
                    builder.Append("<td>" + parentCateName + "</td>");
                    builder.Append("<td>" + cate.MetaKeyword + "</td>");
                    builder.Append("<td>" + status + "</td>");

                    builder.Append("<td><span style=\"color:Blue; cursor:pointer\" title=\"" + cateName + "\" id=\"" + cate.MetaKeyword + "\"  onclick=\"ShowInfoCategory('" + cate.CategoryID + "','" + cate.ParentCategoryID + "','" + cateImage + "',this.title,this.id,'" + cate.IsSection + "')\">Chỉnh sữa</span></td>");
                    builder.Append("<td>");
                    if (cate.IsVisible == 1)
                    {
                        builder.Append("<input type=\"button\" title=\"" + cate.CategoryID + "\"  value=\"Khóa\" onclick=\"LockAndUnlockCategory(this.title,'lock','" + vt + "')\" />");
                    }
                    else
                    {
                        builder.Append("<input type=\"button\" title=\"" + cate.CategoryID + "\"  value=\"Mở khóa\" onclick=\"LockAndUnlockCategory(this.title,'unlock','" + vt + "')\" />");

                    }
                    builder.Append("</td>");
                    Response.Write(builder);
                }
                else
                {
                    Response.Write("unlockfaile");
                }
            }
            Response.End();
        }
        catch
        {

        }
    }
}